package com.hsgene.message.controller;

import com.hsgene.common.util.resolver.IgnoreUserToken;
import com.hsgene.common.util.result.ApiResult;
import com.hsgene.message.service.TripartiteRequestService;
import com.hsgene.mq.constant.MqErrorCode;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 三方请求因子网
 *
 * @author wxf
 * @date 2018/12/11 14:10
 **/
@RestController
@RequestMapping("/v1.0/genetic/testing/tripartite/request")
public class TripartiteRequestController {

    /**
     * Log
     */
    private static Logger LOGGER = LogManager.getLogger(TripartiteRequestController.class);

    @Resource
    private TripartiteRequestService requestService;

    /**
     * 发送机构检测信息
     *
     * @param orderId 机构
     * @return
     */
    @GetMapping("agency/order")
    @IgnoreUserToken
    public ApiResult<Object> sendAgencyOrderInfo(String orderId) {
        try {
            if (StringUtils.isEmpty(orderId)) {
                return ApiResult.fail(MqErrorCode.AGENCY_ID_IS_NOT_NULL);
            }
            String result = requestService.sendAgencyOrderInfo(orderId);
            if (result == null) {
                return ApiResult.fail(MqErrorCode.AGENCY_ORDER_IS_NULL);
            }
            return new ApiResult(200, "success", "机构订单信息推送成功", result);
        } catch (Exception e) {
            LOGGER.error("get agency order info is error...", e);
            return ApiResult.fail(MqErrorCode.AGENCY_SEND_IS_EXCEPTION);
        }
    }
}
